#!/usr/bin/perl
# For example, when the list is sorted into alphabetical order, COLIN, which is worth 3 + 15 + 12 + 9 + 14 = 53, is the 938th name in the list. So, COLIN would obtain a score of 938  53 = 49714.
#
# What is the total of all the name scores in the file?
#

# 2010-04-04
sub worth {
    my $name = $_[0];
    my @words = split //, $name;
    my $sum = 0;
    foreach my $w (@words) {
	$sum = $sum + (ord( $w) - ord ("A") + 1);
    }
    return $sum;
}

while( <> ) {
	chomp;
	$_ =~ s/"//g;
	@names = split /,/, $_;
	my @sorted_name = sort @names;
	my $i = 0;
	my $sum = 0;
	foreach my $name(@sorted_name) {
		$i++;
		# print $name," ",  $i, "\n";
		$sum = $sum + ($i * &worth($name));
	}
	print $sum, "\n";
}
